# Maintainer: Eclipse Adoptium Package Maintainers <temurin-dev@eclipse.org>
pkgname=temurin-19
pkgver=19.0.2_p7
# replace _p1 with _1
_pkgver=${pkgver/_p/_}
# _pkgver=19_36 # remove this line and uncomment the above line when the next version is released
_pkgverplus=${pkgver/_p/+}
# _pkgverplus=19+36 # remove this line and uncomment the above line when the next version is released
_pkgvername=${_pkgverplus/+/%2B}
pkgrel=0
pkgdesc="Eclipse Temurin 19"
provider_priority=19
url="https://adoptium.net"
arch="noarch"
license="GPL-2.0-with-classpath-exception"
makedepends="
	alsa-lib-dev
	freetype-dev
	libffi-dev
	libjpeg-turbo-dev
	libx11-dev
	libxext-dev
	libxrandr-dev
	libxrender-dev
	libxt-dev
	libxtst-dev
"
depends=""
subpackages="$pkgname-src:_src:noarch
	$pkgname-jdk:_jdk:x86_64"
source="https://github.com/adoptium/temurin19-binaries/releases/download/jdk-$_pkgvername/OpenJDK19U-jdk_x64_alpine-linux_hotspot_$_pkgver.tar.gz

	HelloWorld.java
	TestECDSA.java
	TestCryptoLevel.java
"

_java_home="/usr/lib/jvm/java-19-temurin"

ldpath="$_java_home/lib:$_java_home/lib/server"
sonameprefix="$pkgname:"

prepare() {
	default_prepare
}

check() {
	local _java_bin="./jdk-$_pkgverplus/bin"

	# 1) compile and run a simple hello world
	$_java_bin/javac -d . "$srcdir"/HelloWorld.java
	$_java_bin/java HelloWorld

	# 2) compile and run a testcase for unlimited policy
	$_java_bin/javac -d . "$srcdir"/TestCryptoLevel.java
	$_java_bin/java -cp . --add-opens java.base/javax.crypto=ALL-UNNAMED TestCryptoLevel

	# 3) compile and run a testcase for ECDSA signatures
	$_java_bin/javac -d . "$srcdir"/TestECDSA.java
	$_java_bin/java TestECDSA
}

package() {
	mkdir -p "$pkgdir/$_java_home"
	cp -r "$srcdir"/jdk-"$_pkgverplus"/* "$pkgdir/$_java_home"
}

_src() {
	pkgdesc="Eclipse Temurin 19 (sources)"
	mkdir -p "$subpkgdir/$_java_home"/lib
	mv "$pkgdir"/$_java_home/lib/src.zip \
		"$subpkgdir"/$_java_home/lib/
}

_jdk() {
	pkgdesc="Eclipse Temurin 19 (JDK)"
	provides="java-jdk java-jre"
	depends="java-common java-cacerts"
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot"
	mv "$_fromroot/bin"     "$_toroot"
	mv "$_fromroot/conf"    "$_toroot"
	mv "$_fromroot/include" "$_toroot"
	mv "$_fromroot/jmods"   "$_toroot"
	mv "$_fromroot/legal"   "$_toroot"
	mv "$_fromroot/lib"     "$_toroot"
	mv "$_fromroot/man"     "$_toroot"
	mv "$_fromroot/release" "$_toroot"
	mv "$_fromroot/NOTICE"  "$_toroot"

	# symlink to shared cacerts store
	rm "$_toroot/lib/security/cacerts"
	ln -sf /etc/ssl/certs/java/cacerts \
		"$_toroot/lib/security/cacerts"
}

sha256sums="
e2d971400ad2db25ad43ea6fa2058b269c0236e3977986dcdee2097da301beb2  OpenJDK19U-jdk_x64_alpine-linux_hotspot_$_pkgver.tar.gz
e9185736dde99a4dc570a645a20407bdb41c1f48dfc34d9c3eb246cf0435a378  HelloWorld.java
22d2ff9757549ebc64e09afd3423f84b5690dcf972cd6535211c07c66d38fab0  TestCryptoLevel.java
9fb00c7b0220de8f3ee2aa398459a37d119f43fd63321530a00b3bb9217dd933  TestECDSA.java
"
